package com.xhs.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.xhs.dto.request.SendHttpParam;
import com.xhs.message.ReturnResult;
import com.xhs.service.HttpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @desc:
 * @projectName: http-test-api
 * @author: xhs
 * @date: 2024-06-10 14:46
 * @version: JDK 1.8
 */
@Slf4j
@Service
public class HttpServiceImpl implements HttpService {

    /**
     * 发送Get请求 无参
     *
     * @return ReturnResult<Object>
     */
    @Override
    public ReturnResult<Object> sendGet() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", "张三");
        jsonObject.put("phone", "13298297980");
        jsonObject.put("email", "1329829798@qq.com");
        log.info("<--------------------发送Get请求 无参-------------------->");
        return ReturnResult.success().setData(jsonObject);
    }

    /**
     * 发送Get请求 有参
     *
     * @param httpCode 接口编号
     * @param httpUrl  接口地址
     * @return ReturnResult
     */
    @Override
    public ReturnResult<Object> sendGetParam(String httpCode, String httpUrl) {
        log.info("<--------------------发送Get请求 有参-------------------->");
        log.info("<--------------------httpCode:{},httpUrl:{}-------------------->", httpCode, httpUrl);
        return ReturnResult.success().setData(httpCode);
    }

    /**
     * 发送post请求 无参
     *
     * @return ReturnResult
     */
    @Override
    public ReturnResult<Object> sendPost() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("name", "张三");
        jsonObject.put("phone", "13298297980");
        jsonObject.put("email", "1329829798@qq.com");
        log.info("<--------------------发送post请求 无参-------------------->");
        return ReturnResult.success().setData(jsonObject);
    }

    /**
     * 发送post请求 有参 json格式
     *
     * @param param 入参
     * @return ReturnResult
     */
    @Override
    public ReturnResult<Object> sendPostJsonParam(SendHttpParam param) {
        log.info("<--------------------发送post请求 有参 json格式-------------------->");
        log.info("<--------------------param:{}-------------------->", JSONObject.toJSONString(param));
        return ReturnResult.success().setData(param);
    }
}
